package com.zhuqiao.server1.service;

import com.zhuqiao.server1.entity.Test;
import com.zhuqiao.server1.mapper.TestMapper;
import com.zhuqiao.server1.utils.HttpClientResult;
import com.zhuqiao.server1.utils.HttpClientUtil;
import com.zhuqiao.tm.annotation.GlobalTransactional;
import com.zhuqiao.tm.transactional.MyTransactionManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.Map;

@Service
public class TestService {
    @Autowired
    private TestMapper testMapper;

    @GlobalTransactional(isStart = true, total = "2")
    @Transactional
    public void aa() {
        Test test = new Test();
        test.setNum(1);
        test.setName("server1");
        testMapper.insert(test);
        try {
            Map<String, String> headers = new HashMap<>();
            headers.put("groupId", MyTransactionManager.getCurrentGroupId());
            headers.put("transactionCount", MyTransactionManager.getTransactionCount());
            HttpClientResult result = HttpClientUtil.doGet("http://localhost:8082/test/aa", headers, null);
            System.out.println(result);
        } catch (Exception e) {
            e.printStackTrace();
        }

//        int a = 10 / 0;
    }
}
